package cn.com.victorysoft.ylgl.service.commons.mybatis;

import cn.com.victorysoft.ylgl.service.commons.domain.BaseEntity;
import cn.com.victorysoft.ylgl.service.commons.mybatis.mapping.Sort;
import cn.com.victorysoft.ylgl.service.commons.mybatis.paging.bean.DataPaging;
import cn.com.victorysoft.ylgl.service.commons.mybatis.paging.bean.Pageable;
import org.apache.ibatis.session.SqlSession;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import javax.sql.DataSource;
import java.util.List;

/***
 * @author gechaoqing
 */
@Repository
public class MybatisRepository
{
    private SqlSession sqlSession;
    @Resource
    private SqlSessionDao sqlSessionDao;

    @Resource
    public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate)
    {
        this.sqlSession = sqlSessionTemplate;
    }

    public SqlSession getSqlSession()
    {
        return this.sqlSession;
    }

    public DataSource getDataSource()
    {
        return this.sqlSession.getConfiguration().getEnvironment().getDataSource();
    }

    private <T extends BaseEntity> T findById(Class<T> entityClass, String id)
    {
        return null;
    }

    private <T extends BaseEntity> List<T> findByIds(Class<T> entityClass, String[] ids)
    {
        return null;
    }

    private <T extends BaseEntity> List<T> findByIdsAndSorting(Class<T> entityClass, String[] ids, Sort sort)
    {
        return null;
    }

    private <T extends BaseEntity> List<T> findByParams(Class<T> entityClass, Object params)
    {
        return null;
    }

    private <T extends BaseEntity> List<T> findByParamsAndSorting(Class<T> entityClass, Object params, Sort sort)
    {
        return null;
    }

    private <T extends BaseEntity> DataPaging<T> findPaging(Class<T> entityClass, Pageable pageable)
    {
        return null;
    }

    private <T extends BaseEntity> void insert(T entity) {}

    private <T extends BaseEntity> void insert(List<T> entities) {}

    private <T extends BaseEntity> void updateById(T entity) {}

    private <T extends BaseEntity> void updateById(List<T> entities) {}

    private <T extends BaseEntity> void delete(Class<T> entityClass, String id) {}

    private <T extends BaseEntity> void delete(Class<T> entityClass, String[] ids) {}

    private <T extends BaseEntity> void delete(T entity) {}

    public <T> T selectById(String statement, String id)
    {
        return this.sqlSessionDao.selectById(statement, id);
    }

    public <T> T selectOne(String statement, Object key)
    {
        return this.sqlSessionDao.selectOne(statement, key);
    }

    public <E> List<E> selectByParams(String statement, Object params)
    {
        return this.sqlSessionDao.selectByParams(statement, params);
    }

    public <E> DataPaging<E> selectPaging(String statement, Pageable pageable)
    {
        return this.sqlSessionDao.selectPaging(statement, pageable);
    }

    public void insert(String statement, Object params)
    {
        this.sqlSessionDao.insert(statement, params);
    }

    public void update(String statement, Object params)
    {
        this.sqlSessionDao.update(statement, params);
    }

    public void delete(String statement, Object params)
    {
        this.sqlSessionDao.delete(statement, params);
    }
}
